package com.easemob.server.example;

import com.easemob.server.example.api.*;
import com.easemob.server.example.comm.ClientContext;
import com.easemob.server.example.comm.EasemobRestAPIFactory;
import com.easemob.server.example.comm.body.IMUserBody;
import com.easemob.server.example.comm.wrapper.BodyWrapper;

public class Main {

    public static void main(String[] args) throws Exception {

//		System.out.println(EasemobInitialize.getEasemobInitialize().getUSER());
//		EasemobRestAPIFactory factory = ClientContext.getInstance().init(ClientContext.INIT_FROM_PROPERTIES).getAPIFactory();
//		IMUserAPI user = (IMUserAPI)factory.newInstance(EasemobRestAPIFactory.USER_CLASS);
//		ChatMessageAPI chat = (ChatMessageAPI)factory.newInstance(EasemobRestAPIFactory.MESSAGE_CLASS);
//		FileAPI file = (FileAPI)factory.newInstance(EasemobRestAPIFactory.FILE_CLASS);
//		SendMessageAPI message = (SendMessageAPI)factory.newInstance(EasemobRestAPIFactory.SEND_MESSAGE_CLASS);
//		ChatGroupAPI chatgroup = (ChatGroupAPI)factory.newInstance(EasemobRestAPIFactory.CHATGROUP_CLASS);
//		ChatRoomAPI chatroom = (ChatRoomAPI)factory.newInstance(EasemobRestAPIFactory.CHATROOM_CLASS);
//		String EaseUserName = "stat18223960536";// 生成环信用户名
//		String EasePassWord = "stat18223960536";// 生成环信密码 （默认密码和用户名相同）
//		BodyWrapper userBody = new IMUserBody(EaseUserName, EasePassWord, "");
//		Object object = user.createNewIMUserSingle(userBody);
//		System.out.println(object);

//		long phone = 13000001001l;
//		for(int i = 1; i < 2000; i ++) {
//			phone ++;
//			String EaseUserName = "easemob" + phone;// 生成环信用户名
//			String EasePassWord = "easemob" + phone;// 生成环信密码 （默认密码和用户名相同）
//			BodyWrapper userBody = new IMUserBody(EaseUserName, EasePassWord, "");
//			Object object = user.createNewIMUserSingle(userBody);
//			System.out.println(object);
//		}
//        ResponseWrapper fileResponse = (ResponseWrapper) file.uploadFile(new File("d:/logo.png"));
//        String uuid = ((ObjectNode) fileResponse.getResponseBody()).get("entities").get(0).get("uuid").asText();
//        String shareSecret = ((ObjectNode) fileResponse.getResponseBody()).get("entities").get(0).get("share-secret").asText();
//        InputStream in = (InputStream) ((ResponseWrapper) file.downloadFile(uuid, shareSecret, false)).getResponseBody();
//        FileOutputStream fos = new FileOutputStream("d:/logo1.png");
//        byte[] buffer = new byte[1024];
//        int len1 = 0;
//        while ((len1 = in.read(buffer)) != -1) {
//            fos.write(buffer, 0, len1);
//        }
//        fos.close();

    //创建群组
    //String []users = {"18223960536","easemob15520133859","easemob15178889347"};
    //ChatGroupBody chatGroupBody = new ChatGroupBody("first", "暂无", false, (long)200, false, "lovely3x", users);
    //Object obj = chatgroup.createChatGroup(chatGroupBody);
    //ChatRoomBody chatroombody = new ChatRoomBody("first", "", (long) 100, "lovely3x", users);
    //Object obj = chatroom.createChatRoom(chatroombody);
    //System.out.println("--->"+obj + "<----");
    //Object obj = chatgroup.getChatGroupUsers("202703188975944104");
    //Object obj = chatgroup.getChatGroupUsers("202703188975944104");
    //System.out.println("--->"+obj + "<----");
    // Create a IM user
//		BodyWrapper userBody = new IMUserBody("User101", "123456", "HelloWorld");
//		Object obj = user.createNewIMUserSingle(userBody);
//		System.out.println(obj + "--------》1");
//		// Create some IM users
//		List<IMUserBody> users = new ArrayList<IMUserBody>();
//		users.add(new IMUserBody("User002", "123456", null));
//		users.add(new IMUserBody("User003", "123456", null));
//		BodyWrapper usersBody = new IMUsersBody(users);
//		obj = user.createNewIMUserBatch(usersBody);
//		System.out.println(obj + "--------》2");
//		// Get a IM user
    //obj = user.getIMUsersByUserName("easemob15520133859");
    //System.out.println(obj + "--------》3");
//		// Get a fake user
//		obj = user.getIMUsersByUserName("FakeUser001");
//		System.out.println(obj + "--------》4");
//		// Get 12 users
//		obj = user.getIMUsersBatch(null, null);
//		System.out.println(obj + "--------》5");
    //message = Object {id: "208730917210948156", from: "easemob15520133859", to: "easemob18223960530", action: "15520133859", ext: Object}
//		String []users = {"easemob18223960530"};
//		Map<String, String> ext = new HashMap<String, String>();
//		ext.put("type", "cmd");
//		ext.put("action", "15520133859");
//		CommandMessageBody commandMessageBody = new CommandMessageBody("users", 
//				users, "admin", ext, "15520133859");
//		Object  obj = message.sendMessage(commandMessageBody);
//		System.out.println(obj);
//		Object obj = user.disconnectIMUser("easemob18223960530");
//		System.out.println(obj);
//		ChatGroupBody chatGroupBody = new ChatGroupBody("third", "暂无", false, (long)200, false, "", null);
//		obj = chatgroup.modifyChatGroup("203089851157840316", chatGroupBody);
//		System.out.println(obj);
//		Object obj1 = chat.exportChatMessages((long)50, "", "select+*+where+timestamp>1466415685230");
//		System.out.println(obj1);
//		ChatMessageBody chatMessageBody = new ChatMessageBody(1000, "", "");
//		Object obj = chat.exportChatMessages(chatMessageBody);
//		System.out.println(obj + "-------->");
//		String ss = "MTQzNjgyOTEyMDpnR2tBQVFNQWdHa0FCZ0ZWYmdZZER3Q0FkUUFRNF8tUXJqYnJFZWFzZnk5bFc5YkN4d0NBZFFBUTRfLVFwRGJyRWVhbVB3RmlPVFZ2OXdB";
//		System.out.println(ss.length());
//		IMUserAPI imUserAPI = EasemobInitialize.getEasemobInitialize().getUSER();
//		Object object = imUserAPI.getIMUsersByUserName("easemob1552013385");
//		System.out.print(object);
    //Response Body: {"action":"get","path":"/users","uri":"http://a1.easemob.com/chongqing-langruisi/yzj/users/easemob15520133859","entities":[{"uuid":"6e51d9da-215a-11e6-8986-4fc3659796d3","type":"user","created":1464058296301,"modified":1468127652445,"username":"easemob15520133859","activated":true}],"timestamp":1468132998144,"duration":5,"count":1}
}
}
